home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / skyline / example / second.c < prev   
Encoding:
C/C++ Source or Header  |  1994-08-02  |  636 b   |  31 lines

  1.  
  2. #include <sys/time.h>
  3.  
  4. /* **********************************************************************
  5.  
  6.    give the elapsed wall clock time
  7.  
  8. ********************************************************************** */
  9. float second_()
  10. {
  11.         struct timeval s_val;
  12.     struct timezone s_z;
  13.  
  14.     static float zero_time = 0.0;
  15.     static long zero_sec = 0;
  16.     float time;
  17.     long n_sec, n_usec;
  18.  
  19.         gettimeofday(&s_val, &s_z);
  20.  
  21.     n_sec = s_val.tv_sec;
  22.     n_usec = s_val.tv_usec;
  23.     if( zero_time == 0.0 ) {
  24.         zero_sec = n_sec;
  25.         zero_time = 1.0e-6 * (float)n_usec;
  26.     }
  27.     time = (float)(n_sec-zero_sec) + (float)n_usec * 1.0E-6 - zero_time;
  28.     return( time );
  29. }
  30.  
  31.